﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mapster;
using Newtonsoft.Json;
using YShop.Application.Contracts.Shop;
using YShop.Core.Entites;

namespace YShop.Application.MapperProfiles
{
    public class ShopMapperProfiles : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<Product, ProductDto>()
                .Map(d => d.Options, s => JsonConvert.DeserializeObject<List<ProductAttributeDto>>(s.Options));
            config.ForType<ProductDto, Product>()
                .Map(d => d.Options, s => JsonConvert.SerializeObject(s.Options));
        }
    }
}
